package com.happyhome.services;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.happyhome.constants.ComTxManagerName;
import com.happyhome.dao.HouseUtilityDao;
import com.happyhome.datamodel.HouseUtility;

@Service
public class HouseUtilityServiceImpl implements HouseUtilityService {

	@SuppressWarnings("unused")
	private static final Logger logger = LoggerFactory.getLogger(HouseUtilityServiceImpl.class);

	@Autowired
	private HouseUtilityDao houseUtilityDao;

	@Override
	@Transactional(value = ComTxManagerName.COM_TRANSACTION_MANAGER)
	public HouseUtility merge(HouseUtility house) {
		return houseUtilityDao.merge(house);
	}

	@Override
	public List<Object[]> getAllUtilityByHouseId(Long houseId) {
		return houseUtilityDao.getAllUtilityByHouseId(houseId);
	}

	@Override
	@Transactional(value = ComTxManagerName.COM_TRANSACTION_MANAGER)
	public void deleteAllUtilitiesHouseUtility(Long houseId) {
		List<HouseUtility> houseUtilities = houseUtilityDao.getAllUtilitiesOfHouse(houseId);
		for(HouseUtility houseUtility: houseUtilities){
			houseUtilityDao.remove(houseUtility);
		}
	}
}
